<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>评测</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" type="text/css" href="../res/layui/css/layui.css" th:href="@{/res/layui/css/layui.css}">
    <link rel="stylesheet" type="text/css" href="../res/css/main.css" th:href="@{/res/css/main.css}">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <form class="layui-form" action="" method="post">
                <p style="margin-top: 50px"></p>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">测评用户</label>
                        <div class="layui-input-inline">
                            <input type="text" id="userOp" name="userOp" placeholder="请输入评测用户" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn" lay-submit lay-filter="queryForm" style="margin-left: 120px">立即查询
                        </button>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <!--表格-->
            <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
            <script type="text/html" id="table-content-list">
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script src="../layuiadmin/layui/layui.js" th:src="@{/layuiadmin/layui/layui.js}"></script>
<script type="text/javascript">
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use('index', function () {
    });
</script>
<script>
    layui.use(['table', 'form'], function (exports) {
        var $ = layui.$, table = layui.table, form = layui.form;
        //表格
        table.render({
            elem: '#LAY-app-content-list'
            , url: '/admin/pgtest/list'//模拟接口
            , cols: [
                [
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'id', width: 120, title: 'ID', sort: true}
                    , {field: 'pgtestResult', title: '测评结果', width: 250}
                    , {field: 'pgtestScore', title: '测评分数', width: 130}
                    , {field: 'pgtestTime', title: '测评时间', width: 160}
                    , {field: 'userOp', title: '测评用户', align: 'center'}
                    , {title: '操作', minWidth: 250, align: 'center', fixed: 'right', toolbar: '#table-content-list'}
                ]
            ]
            , page: true
            , limit: 10
            , height: 'full-220'
            , text: '对不起，加载出现异常！'
        });


        //监听查询点击事件
        form.on('submit(queryForm)', function (data) {
            table.render({
                elem: '#LAY-app-content-list'
                ,
                height: 312
                ,
                url: '/admin/pgtest/list?keyword1=' + data.field.userOp//后台数据接口
                ,
                page: true
                ,
                cols: [
                    [
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'id', width: 120, title: 'ID', sort: true}
                        , {field: 'pgtestResult', title: '测评结果', width: 250}
                        , {field: 'pgtestScore', title: '测评分数', width: 130}
                        , {field: 'pgtestTime', title: '测评时间', width: 160}
                        , {field: 'userOp', title: '测评用户', align: 'center'}
                        , {title: '操作', minWidth: 250, align: 'center', fixed: 'right', toolbar: '#table-content-list'}
                    ]
                ]
            });
            return false;
        });
        //监听行工具事件
        table.on('tool(LAY-app-content-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除ID为\t' + data.id + "\t的评测记录吗！", function (index) {
                    //异步像服务器发送删除请求
                    $.ajax({
                        url: '/admin/pgtest/del',
                        type: 'GET',
                        data: {'id': data.id},
                        success: function (result) {
                            console.log("数据返回成功！" + result.success)
                            if (result.status == true) {
                                layer.msg("删除成功!" + result, {icon: 6});
                                obj.del();
                                layer.close(index);
                                location.reload();
                            } else {
                                layer.msg("删除失败!" + result, {icon: 5});
                                layer.close(index);
                            }
                        },
                        error: function (errorMsg) {
                            layer.msg("数据异常!" + errorMsg, {icon: 5});
                            layer.close(index);
                            location.reload();
                        },
                    });
                });
            }
        });
    });
</script>
</body>
</html>
